Skip to content

Declare tentative return types for ext/spl - part 2 #7235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Jul 13, 2021

No description provided.

@kocsismate kocsismate force-pushed the tentative-return-type-22 branch from fe8902b to 9ef94bf Compare July 14, 2021 11:06
@kocsismate kocsismate added the Tentative returns Temporary label for tentative return follow ups label Jul 14, 2021
Copy link
Member

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few methods here that should really be void, but I guess we should just go with this.

@kocsismate kocsismate deleted the tentative-return-type-22 branch July 14, 2021 13:20
/** @return int */
public function key() {}
/** @tentative-return-type */
public function key(): int {}
Copy link
Contributor

@TysonAndre TysonAndre Jul 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an application I use, I can easily refactor a current subclass of SplObjectStorage to use composition instead of inheritance https://github.com/phan/phan/blob/v5/src/Phan/Library/Map.php#L30-L40 ( at the cost of a bit of speed) and suppress for now via annotation

But I wonder how many things override SplObjectStorage right now to change key/current to something else in the absense of a native Map type for objects outside of ds/its polyfill.

Aside: Would it make sense to add a new method SplObjectStorage->currentValue() to avoid the need to call $splObjectStorage->offsetGet($splObjectStorage->current())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I hate the interface that SplObjectStorage exposes (it probably is that way because it predates the non-int/string iterator key support I added in PHP 5.5 or so), your class still clearly violates the API -- if something accepts an SplObjectStorage and is passed your Map instead, it will not behave correctly. So I do think that switching the implementation to use composition would be the right move here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, It turns out the functionality I was thinking of already exists as https://www.php.net/manual/en/splobjectstorage.getinfo.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tentative returns Temporary label for tentative return follow ups
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants